package com.cskaoyan.config2;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 成员变量中的值从配置文件中来
 * @author stone
 * @date 2022/07/15 10:20
 */
@Configuration
public class DataSourceConfiguration2 {

    @Value("${cskaoyan.datasource.driver-class-name}")
    String driverClassName;  //"com.mysql.jdbc.Driver";
    @Value("${cskaoyan.datasource.url}")
    String url;  //"jdbc:mysql://localhost:3306/cskaoyan_db?useUnicode=true&characterEncoding=utf-8";
    @Value("${cskaoyan.datasource.username}")
    String username;  //"root";
    @Value("${cskaoyan.datasource.password}")
    String password;  //"123456";
    @Bean
    public DataSource dataSource2() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
